import { App } from 'vue';
import MedicalEditor from './components/MedicalEditor.vue';
import Toolbar from './components/Toolbar.vue';
import MedicalNavigator from './components/MedicalNavigator.vue';
import TermSuggestion from './components/medical/TermSuggestion.vue';
import { useEditorStore } from './stores/editorStore';
import { useTemplateStore } from './stores/templateStore';

// 导入样式
import './assets/styles/index.scss';
import { fromFhirFormat, toFhirFormat } from './utils/medicalFormat';
import { defaultOptions } from './defaultOptions';

// 定义插件
const MedicalEditorPlugin = {
  install(app: App, options = {}) {
    // 注册全局组件
    app.component('MedicalEditor', MedicalEditor);
    app.component('MedicalToolbar', Toolbar);
    app.component('MedicalNavigator', MedicalNavigator);
    app.component('TermSuggestion', TermSuggestion);
    
    // 注册全局状态
    const editorStore = useEditorStore();
    
    // Type the template store explicitly
    const templateStore = useTemplateStore();
    
    // 合并配置选项
    const mergedOptions = {
      ...defaultOptions,
      ...options
    };
    
    // 设置全局配置
    editorStore.setConfig(mergedOptions.editor);
    
    // 注册全局工具函数
    app.config.globalProperties.$medicalFormat = {
      toFhirFormat,
      fromFhirFormat
    };
  }
};

// 导出单个组件
export { 
  MedicalEditor, 
  Toolbar, 
  MedicalNavigator, 
  TermSuggestion 
};

// 导出状态管理
export { useEditorStore, useTemplateStore };

// 导出工具函数
export * from './utils/medicalFormat';
export * from './utils/fileUtils';

// 导出类型定义
export * from './types/medicalTypes';

// 导出默认配置
export { defaultOptions } from './defaultOptions';

// 导出插件
export default MedicalEditorPlugin;